package com.btshop.goods.controller;
import com.btshop.goods.pojo.Album;
import com.btshop.goods.service.AlbumService;
import com.github.pagehelper.PageInfo;
import com.util.Result;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName: AlbumController
 * @description: Album 控制层接口定义类
 * @author: 李东
 * @Date: 2020-7-20
 */
@Api(value = "AlbumController")
@Slf4j
@RestController
@RequestMapping("/album")
@CrossOrigin
public class AlbumController {

    @Autowired
    private AlbumService albumService;

    /***
     * Album分页条件搜索实现
     * @param album
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "Album条件分页查询",notes = "分页条件查询Album方法详情",tags = {"AlbumController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "Album对象",value = "传入JSON数据",required = false) Album album, @PathVariable  int page, @PathVariable  int size){
        log.info("AlbumController findPage params , album : {} , page : {} , size : {}",album,page,size);
        //调用AlbumService实现分页条件查询Album
        PageInfo<Album> pageInfo = albumService.findPage(album, page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * Album分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "Album分页查询",notes = "分页查询Album方法详情",tags = {"AlbumController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        log.info("AlbumController findPage params , page : {} , size : {}",page,size);
        //调用AlbumService实现分页查询Album
        PageInfo<Album> pageInfo = albumService.findPage(page, size);
        return Result.buildSuccess("查询成功！", pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param album
     * @return
     */
    @ApiOperation(value = "Album条件查询",notes = "条件查询Album方法详情",tags = {"AlbumController"})
    @PostMapping(value = "/search" )
    public Result<List<Album>> findList(@RequestBody(required = false) @ApiParam(name = "Album对象",value = "传入JSON数据",required = false) Album album){
        log.info("AlbumController findList params , album : {} ",album);
        //调用AlbumService实现条件查询Album
        List<Album> list = albumService.findList(album);
        return Result.buildSuccess("查询成功！", list);
    }

    /***
     * 根据主键删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Album根据主键id删除",notes = "根据主键删除Album方法详情",tags = {"AlbumController"})
    @ApiImplicitParams({
                @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
    })
    @DeleteMapping(value = "/{id}")
    public Result delete(@PathVariable("id") Long id){
        log.info("AlbumController delete params ,   id : {}   ",id);
        //调用AlbumService实现根据主键删除
        albumService.delete(id);
        return Result.buildSuccess("删除成功！");
    }

    /***
     * 修改Album数据
     * @param album
     * @param id
     * @return
     */
    @ApiOperation(value = "Album根据id修改",notes = "根据ID修改Album方法详情",tags = {"AlbumController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
     })
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "Album对象",value = "传入JSON数据",required = false) Album album,@PathVariable("id") Long id){
        log.info("AlbumController update params ,  album : {},  id : {}   ",album,id);
        //设置主键值
        album.setId(id);
        //调用AlbumService实现修改Album
        albumService.update(album);
        return Result.buildSuccess("修改成功！");
    }

    /***
     * 新增Album数据
     * @param album
     * @return
     */
    @ApiOperation(value = "Album添加",notes = "添加Album方法详情",tags = {"AlbumController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "Album对象",value = "传入JSON数据",required = true) Album album){
        log.info("AlbumController add params , album : {}",album);
        //调用AlbumService实现添加Album
        albumService.add(album);
        return Result.buildSuccess("添加成功！");
    }

    /***
     * 根据ID查询Album数据
     * @param id
     * @return
     */
    @ApiOperation(value = "Album根据id查询",notes = "根据ID查询Album方法详情",tags = {"AlbumController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name ="id", value = "主键", required = true, dataType = "Long")
            })
    @GetMapping("/{id}")
    public Result<Album> findById(@PathVariable("id") Long id){
        log.info("AlbumController findById params ,   id : {}   ",id);
        //调用AlbumService实现根据主键查询Album
        Album album = albumService.findById(id);
        return Result.buildSuccess("查询成功！",album);
    }

    /***
     * 查询Album全部数据
     * @return
     */
    @ApiOperation(value = "查询所有Album",notes = "查询所Album有方法详情",tags = {"AlbumController"})
    @GetMapping
    public Result<List<Album>> findAll(){
        //调用AlbumService实现查询所有Album
        List<Album> list = albumService.findAll();
        return Result.buildSuccess("查询成功！",list);
    }
}
